home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OCLIEN.PAK / FRAME.CPP next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  171 lines

  1. // frame.cpp : implementation of the CMainFrame class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13.  
  14.  
  15. #include "stdafx.h"
  16. #include "oclient.h"
  17.  
  18. #include "frame.h"
  19.  
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CMainFrame
  27.  
  28. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  29.  
  30. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  31.     //{{AFX_MSG_MAP(CMainFrame)
  32.     ON_WM_CREATE()
  33.     ON_COMMAND(ID_WINDOW_TILE_HORZ, OnWindowTileHorz)
  34.     ON_WM_PALETTECHANGED()
  35.     ON_WM_QUERYNEWPALETTE()
  36.     //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // arrays of IDs used to initialize control bars
  41.  
  42. // toolbar buttons - IDs are command buttons
  43. static UINT BASED_CODE buttons[] =
  44. {
  45.     // same order as in the bitmap 'toolbar.bmp'
  46.     ID_FILE_NEW,
  47.     ID_FILE_OPEN,
  48.     ID_FILE_SAVE,
  49.         ID_SEPARATOR,
  50.     ID_EDIT_CUT,
  51.     ID_EDIT_COPY,
  52.     ID_EDIT_PASTE,
  53.         ID_SEPARATOR,
  54.     ID_FILE_PRINT,
  55.     ID_APP_ABOUT,
  56.     ID_CONTEXT_HELP,
  57. };
  58.  
  59. static UINT BASED_CODE indicators[] =
  60. {
  61.     ID_SEPARATOR,           // status line indicator
  62.     ID_INDICATOR_CAPS,
  63.     ID_INDICATOR_NUM,
  64.     ID_INDICATOR_SCRL,
  65. };
  66.  
  67.  
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CMainFrame construction/destruction
  70.  
  71. CMainFrame::CMainFrame()
  72. {
  73. }
  74.  
  75. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  76. {
  77.     if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  78.         return -1;
  79.  
  80.     if (!m_wndToolBar.Create(this) ||
  81.         !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  82.         !m_wndToolBar.SetButtons(buttons,
  83.           sizeof(buttons)/sizeof(UINT)))
  84.     {
  85.         TRACE0("Failed to create toolbar\n");
  86.         return -1;      // fail to create
  87.     }
  88.  
  89.     if (!m_wndStatusBar.Create(this) ||
  90.         !m_wndStatusBar.SetIndicators(indicators,
  91.           sizeof(indicators)/sizeof(UINT)))
  92.     {
  93.         TRACE0("Failed to create status bar\n");
  94.         return -1;      // fail to create
  95.     }
  96.     EnableDocking(CBRS_ALIGN_ANY);
  97.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  98.     DockControlBar(&m_wndToolBar);
  99. #ifndef _MAC
  100.     CDC* pDC = GetDC();
  101.     m_palette.CreateHalftonePalette(pDC);
  102.     ReleaseDC(pDC);
  103. #endif // !_MAC
  104.     return 0;
  105. }
  106.  
  107. CMainFrame::~CMainFrame()
  108. {
  109. }
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CMainFrame diagnostics
  113.  
  114. #ifdef _DEBUG
  115. void CMainFrame::AssertValid() const
  116. {
  117.     CMDIFrameWnd::AssertValid();
  118. }
  119.  
  120. void CMainFrame::Dump(CDumpContext& dc) const
  121. {
  122.     CMDIFrameWnd::Dump(dc);
  123. }
  124.  
  125. #endif //_DEBUG
  126.  
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CMainFrame commands
  129.  
  130. void CMainFrame::OnWindowTileHorz()
  131. {
  132.     if (GetKeyState(VK_SHIFT) < 0)
  133.         OnMDIWindowCmd(ID_WINDOW_TILE_VERT);
  134.     else
  135.         OnMDIWindowCmd(ID_WINDOW_TILE_HORZ);
  136. }
  137.  
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CMainFrame message handlers
  140.  
  141. void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd) 
  142. {
  143.     CMDIFrameWnd::OnPaletteChanged(pFocusWnd);
  144.     if (pFocusWnd != this)
  145.         SelectPalette(TRUE);
  146. }
  147.  
  148. BOOL CMainFrame::OnQueryNewPalette() 
  149. {
  150.     if (CMDIFrameWnd::OnQueryNewPalette())
  151.         return TRUE;
  152.     return SelectPalette(FALSE);
  153. }
  154.  
  155. BOOL CMainFrame::SelectPalette(BOOL bBackground)
  156. {
  157.     if (m_palette.m_hObject == NULL)
  158.         return FALSE;
  159.  
  160.     CDC* pDC = GetDC();
  161.     CPalette* pOldPal = pDC->SelectPalette(&m_palette, bBackground);
  162.     UINT nPalChg = pDC->RealizePalette();
  163.     pDC->SelectPalette(pOldPal, TRUE); // background
  164.     ReleaseDC(pDC);
  165.                 
  166.     if (nPalChg > 0)
  167.         InvalidateRect(NULL, TRUE);
  168.  
  169.     return TRUE;
  170. }
  171.